import java.util.ArrayList;
import java.util.List;

public class SolutionInterview8_4 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> ans=new ArrayList<>();
        List<Integer> now=new ArrayList<>();
        dfs(ans,0,nums,now);
        return ans;
    }

    private void dfs(List<List<Integer>> ans, int k, int[] nums, List<Integer> now) {
        if (k==nums.length){
            ans.add(new ArrayList<>(now));
            return;
        }
        dfs(ans,k+1,nums,now);
        now.add(nums[k]);
        dfs(ans,k+1,nums,now);
        now.remove(now.size()-1);
    }

    public static void main(String[] args) {
        System.out.println(new SolutionInterview8_4().subsets(new int[]{1,2,3}));
    }
}
